package com.thinkgem.jeesite.modules.bls.service;

import java.util.Date;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.modules.bls.dao.LoanDao;
import com.thinkgem.jeesite.modules.bls.entity.Loan;

/**
 * 信贷申请状态处理器
 *
 * @author edpdennis
 */
@Component
@Transactional
public class AfterModifyApplyContentProcessor implements TaskListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1907586403014936096L;

	@Autowired
	LoanDao loanDao;
	
	@Autowired
	RuntimeService runtimeService;

	public void notify(DelegateTask delegateTask) {
		String processInstanceId = delegateTask.getProcessInstanceId();
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
		Loan loan = loanDao.findOne(new Long(processInstance.getBusinessKey()));
		
		
		loan.setStartdate((Date) delegateTask.getVariable("startdate"));
		loan.setEnddate((Date) delegateTask.getVariable("enddate"));
		loan.setAmount((Float) delegateTask.getVariable("amount"));
	
		loanDao.save(loan);
	}

}
